/**
 * 	feed 操作类
 */

var FeedAction = {
		
		feedtype:'word',
		
		fastSendFeed:function()
		{
			var _fastVal = $.trim($('#fastcontent').val());
			if(_fastVal=="")
			{
				_Cerror('fastcontent',3);
				return;
			}
			
			this.fastContentHide();
			this.loadImgShow();			

			$.ajax({
				  url: "/index.php?r=feed/fastsend",
				  data: {'_fastVal':_fastVal},
				  success: function(data){
						  FeedAction.successShow();
				  },
				  dataType: "json"
				});
		},

		//隐藏发表框
		fastContentShow:function()
		{
			$("#editor-box-fast").show();
			$('#success-module-fast').hide();
		},
		
		//隐藏发表框
		fastContentHide:function()
		{
			$("#editor-box-fast").hide();
		},
		
		//显示load
		loadImgShow:function()
		{
			$("#loading-module-fast").show();
		},

		//关闭load
		loadImgHide:function()
		{
			$("#loading-module-fast").hide();
		},
		
		//显示成功 
		successShow:function()
		{
			this.loadImgHide();
			$('#success-module-fast').show();
			//1秒后消失
			setTimeout(this.fastContentShow,2000);
		},
		
		//发表框相片
		_CfeedSendOfPhoto:function()
		{
			$('#global-publisher-photo-box').show();
			$('#global-publisher-share-box').hide();
			$('.close').show();
		},
		
		//发表框分享
		_CfeedSendOfShare:function()
		{
			$('#global-publisher-share-box').show();
			$('#global-publisher-photo-box').hide();
			$('.close').show();
		},
		
		_CcloseFeedType:function(obj)
		{
			this.feedtype = 'word';
			$('#global-publisher-share-box').hide();
			$('#global-publisher-photo-box').hide();
			$(obj).hide();
		},

		//发表
		_CfeedCoreSend:function()
		{			
			var _fastVal = $.trim($('#corecontent').val());
			var _imgVal = $('#_hide_img_path').val();
			var _usereventval = $('#user_event_val').val();
			
			if(_fastVal=="")
			{
				_Cerror('corecontent',3);
				return;
			}
			
			//一些效果	1.隐藏发表框
			$('#status-editor-core').hide();
			
			//2.打开load
			$('#loading-module-core').show();

			if(this.feedtype == 'photo')
			{
				$.ajax({
					  url: "/index.php?r=feed/photo",
					  data: {'_fastVal':_fastVal,'_imgVal':_imgVal,'_usereventval':_usereventval},
					  success: function(data){
						  FeedAction._CsuccessShowCore();
					  },
					  dataType: "json"
					});				
			}
			else
			{
				$.ajax({
					  url: "/index.php?r=feed/fastsend",
					  data: {'_fastVal':_fastVal,'_usereventval':_usereventval},
					  success: function(data){
						  FeedAction._CsuccessShowCore();
					  },
					  dataType: "json"
					});
			}
		},
		
		_CsuccessShowCore:function()
		{
			  // 3.打开成功框
			  $('#success-module-core').show();
			  $('#loading-module-core').hide();
			  //2秒后消失
			  setTimeout("Boxy.get('.boxyclose').hide()",2000);
		},
		
		//上传图片
		_CfeedCorePhotoSend:function()
		{
			$("#file_changer").uploadify({
				uploader : 'js/plus/uploadify.swf',
				script : 'index.php?r=feed/uploadphoto',
				wmode : 'transparent',
				cancelImg : 'js/plus/cancel.png',
				auto : true,
				hideButton : true,
				onComplete : function(event, ID, fileObj, response, data) {
					FeedAction.feedtype = 'photo';
					var _img_info = '<div class="photo-info">';
					_img_info += '<div class="success-module">';
					_img_info += '<figure class="thumb"><img src="'+response+'"></figure>';
					_img_info += '<p><img src="http://xnimg.cn/n/res/icons/right.png"> 上传成功，请点击发布分享给好友。</p>';
					_img_info += '<input type="hidden" id="_hide_img_path" name="_hide_img_path" value="'+response+'">';
					_img_info += '</div>';
					_img_info += '</div>';
					$('#photo-info-box').html(_img_info);
					$('#photo-info-box').show();
					$('#upload-selector').hide();
					$('#uploading-module-photo').hide();
					if($('#corecontent').val()=="")
						$('#corecontent').val('分享图片');
				},
				onProgress : function(file,e)
				{
					$('#uploading-module-photo').show();
				},
				fileExt : '*.jpg;*.png,*.gif;',
				fileDesc : '图片文件 (.jpg, .png, .gif)',
				width : 140,
				height : 140
			});
		},
		
		//刷新FEED
		_CfeedRefresh:function()
		{
			//yw0
			$('#yw0').html('');
			$('#feed-loading-id').show();
			$.ajax({
				  url: "/index.php",
				  data:"act=refresh",
				  success: function(data){
					  $('#feed-loading-id').hide();
					  $('#yw0').html(data);
				  },
				  dataType: "html"
				});
		},
		
		//点击更多事件
		_CmoreEvent:function()
		{
			$('#layer_menu_list_more').show();
		},
		
		//添加新事件
		_CaddNewEvent:function()
		{
			var _newval = $('#new_user_event_val').val();
			
			if(_newval == '')
			{
				$('#add-event-div').hide();
				$('#new_user_event_val').val('');
				return;
			}
			
			$(".nfTagB ul li").each(function(i){
				var _eachhtml = $(this).children("span").html();
				if(_eachhtml == null)
					_eachhtml = $(this).children("a").html();

				if(i == 3)
				{
					$(this).show();
					$(this).addClass('current').html('<span>'+_newval+'</span>');
					$('#user_event_val').val(_newval);
				}
				else if(i != 3 && i < 4)
				{
					//所有的变成a
					$(this).html('<a href="#nogo" title="'+_eachhtml+'">'+_eachhtml+'</a>');
				}
			});
			
			//隐藏
			$('#add-event-div').hide();
			$('#new_user_event_val').val('');
		}
};

//绑定提交事件
$("#global-publisher-share-trigger-fast-send").live('click',function() {
	FeedAction.fastSendFeed();
});


$(".nfTagB ul li").live('click',function() {
		self = this;
		s = $(self).index();
		var _selfhtml = $(this).children("span").html();
		if(_selfhtml == null)
			_selfhtml = $(this).children("a").html();


			if($(self).attr('id') == 'morebutton')
				return;

		//点击更多的事件
		if($(this).attr('class') == 'more_nfTagB_li')
		{
			$(".nfTagB ul li").each(function(i){
				var _eachhtml = $(this).children("span").html();
				if(_eachhtml == null)
					_eachhtml = $(this).children("a").html();

				if(i == 3)
				{
					$(this).show();
					$(this).addClass('current').html('<span>'+_selfhtml+'</span>');
					$('#user_event_val').val(_selfhtml);
				}
				else if(i != 3 && i < 4)
				{
					//所有的变成a
					$(this).html('<a href="#nogo" title="'+_eachhtml+'">'+_eachhtml+'</a>');
				}
					
			});
			
			$('#layer_menu_list_more').hide();
			
			return;
		}
		
		//点击动作
		if($(this).attr('class') == 'more_nfTagB_li_add')
		{
			$('#add-event-div').show();
			$('#layer_menu_list_more').hide();
			return;
		}

		$(".nfTagB ul li").each(function(i){
			if(i < 4)
			{
				var _eachhtml = $(this).children("span").html();
				if(_eachhtml == null)
					_eachhtml = $(this).children("a").html();

				//所有的变成a
				$(this).html('<a href="#nogo" title="'+_eachhtml+'">'+_eachhtml+'</a>');
				$(self).addClass('current').html('<span>'+_selfhtml+'</span>');
				$('#user_event_val').val(_selfhtml);
			}
		});
});
	